package com.wxzz.elearning.common.utils;

import cn.jiguang.common.resp.ResponseWrapper;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;


import cn.jiguang.common.resp.APIConnectionException;
import cn.jiguang.common.resp.APIRequestException;
import cn.jmessage.api.JMessageClient;
import cn.jmessage.api.chatroom.CreateChatRoomResult;
import cn.jmessage.api.common.model.RegisterInfo;
import cn.jmessage.api.common.model.chatroom.ChatRoomPayload;


@Slf4j
public class ImUtil {

    String appkey = "90404644792112144baf94ae";
    String masterSecret = "246eed9ae3f94a648afad942";
    JMessageClient client = new JMessageClient(appkey, masterSecret);

    /**
     * deleteChatRoom
     */
    @Test
    public void deleteChatRoom(Long roomId) throws APIConnectionException, APIRequestException {
        ResponseWrapper responseWrapper = client.deleteChatRoom(15317450);
        System.out.println(11);
    }

    /**
     * createChatRoom
     */
    @Test
    public void createChatRoom() throws APIConnectionException, APIRequestException {
        CreateChatRoomResult chatRoom = client.createChatRoom(ChatRoomPayload.newBuilder()
                .setOwnerUsername("admin")
                .setName("聊天室2")
                .build());
        Long chatroom_id = chatRoom.getChatroom_id();
        System.out.println(chatRoom);
    }

    /**
     * registerUsers
     */
    @Test
    public void registerUsers() throws APIConnectionException, APIRequestException {
        client.addChatRoomMember(28545412,"15268424213");

        RegisterInfo registerInfo = RegisterInfo.newBuilder()
                .setUsername("hello1")
                .setPassword("hello1")
                .build();
        RegisterInfo[] registerInfos = new RegisterInfo[1];
        registerInfos[0] = registerInfo;
        String string = client.registerUsers(registerInfos);

        System.out.println(string);
    }

    /**
     * registerAdmins
     */
    @Test
    public void registerAdmins() throws APIConnectionException, APIRequestException {

        String string = client.registerAdmins("admin", "admin");
        System.out.println(string);
    }
}
